package singleton.exambook;

public class ChocolateBoiler2 {
	private boolean empty;
	private boolean boiled;
	private volatile static ChocolateBoiler2 uniqueInstance;
	
	private ChocolateBoiler2(){
		this.empty = true;
		this.boiled = false; //보일러가 비어있을 때만
	}
	public static ChocolateBoiler2 getInstance(){
		if(uniqueInstance == null){
			synchronized (ChocolateBoiler2.class) {
				if(uniqueInstance == null){
					return uniqueInstance = new ChocolateBoiler2();
				}
			}
			
		}
		return uniqueInstance;
	}
	public void fill(){
		if(isEmpty()){  /*보일러가 비어있을때만 재료를 집어넣습니다. 원료를 넣으면 false*/
			this.empty = false;
			this.boiled = false;
			/*보일러에 우유/초콜릿을 혼합한 재료를 집어넣음.*/
		}
	}
	public void drain(){
		if(!isEmpty() && isBoiled()){ /*보일러를 다 비우고 나면  empty true*/
			this.empty = true;
		}
	}
	public void boil(){
		if(!isEmpty() && !isBoiled()){
			/*재료를 끓음*/
			this.boiled = true;
		}
	}
	
	public boolean isEmpty(){
		return empty;
	}
	public boolean isBoiled(){
		return boiled;
	}

}
